package com.qf.service.impl;


import com.github.pagehelper.PageHelper;
import com.qf.common.dto.OrderDto;
import com.qf.entity.Order;
import com.qf.exception.ServiceException;
import com.qf.mapper.OrderMapper;
import com.qf.service.OrderService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author KING
 * @ClassName: com.qf.service.impl.OrderServiceImpl
 * @Description: 该类的功能描述
 * @date: 2021/10/27 21:27
 */
@Service
@Slf4j
public class OrderServiceImpl implements OrderService {
    @Resource
    private OrderMapper orderMapper;

    @Override
    public List<Order> findOrders(OrderDto orderDto) {
        //分页
        if (orderDto.getPage() == null) {
            orderDto.setPage(0);
        }
        if (orderDto.getSize() == null) {
            orderDto.setSize(10);
        }
        PageHelper.startPage(orderDto.getPage(), orderDto.getSize());
        List<Order> orderList = null;
        try {
            orderList = orderMapper.selectOrder(orderDto.getStoreId());
            return orderList;
        } catch (ServiceException e) {
            throw new ServiceException(e.getResponseCode());
        }
    }

    @Override
    public List<Order> searchOrders(OrderDto orderDto) {
        //分页
        if (orderDto.getPage() == null) {
            orderDto.setPage(1);
        }
        if (orderDto.getSize() == null) {
            orderDto.setSize(10);
        }
        PageHelper.startPage(orderDto.getPage(), orderDto.getSize());
        Order order = new Order();
        BeanUtils.copyProperties(orderDto, order);
        List<Order> orderList = orderMapper.searchList(order);
        return orderList;
    }

    @Override
    public List<Order> sortOrders(Integer sid, Integer role) {
        List<Order> orderList = orderMapper.selectByPay(sid, role);
        return orderList;
    }
}
